<template>
	<view>
		<swiper indicator-dots circular interval="2000" autoplay>
			<swiper-item v-for="(path) in swiperGoods">
				<image :src="path" ></image>
			</swiper-item>
		</swiper>
		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav_item" @click="toNew">
				<image src="../../static/home.png" mode="widthFix"></image>
				<text>搜索</text>
			</view>
			<view class="nav_item" @click="toCategory">
				<image src="../../static/category.png" mode="widthFix"></image>
				<text>分类</text>
			</view>
			<view class="nav_item" @click="toCart">
				<image src="../../static/cart.png" mode="widthFix"></image>
				<text>购物</text>
			</view>
			<view class="nav_item">
				<image src="../../static/myself.png" mode="widthFix"></image>
				<text>我的</text>
			</view>
		</view>
		<!-- 推荐商品 -->
		<goods-list ref="newgoods" :num="pageNum" :size="pageSize"></goods-list>
	</view>
</template>

<script>
	import goodsList from "../../components/goodslist.vue"
	export default {
		components:{
			goodsList
		},
		data() {
			return {
				swiperGoods:["http://r7hvave5i.hn-bkt.clouddn.com/%E4%B8%8B%E8%BD%BD%20%283%29.jpg",
						"http://r7hvave5i.hn-bkt.clouddn.com/214622-15852303825308.jpg",
						"http://r7hvave5i.hn-bkt.clouddn.com/003219-15968179390d29.jpg"
				],
				pageNum:1,
				pageSize:4
			}
		},
		onShow() {
			this.$refs.newgoods.getHotGoods(this.pageNum,this.pageSize);
		},
		onReachBottom() {
			console.log("我到底了");
			this.pageNum++;
			//调用子页面的刷新下一页方法
			uni.showToast({
				duration: 1500,
				title: '加载中……',
				icon: 'loading',
				success: () => {
					setTimeout( ()=>{
						this.$refs.newgoods.getHotGoods(this.pageNum,this.pageSize);
						uni.hideToast();
					},500)
				}
			})
		},
		methods: {
			toCategory(){
				uni.navigateTo({
					url:"./category",
					success() {
						console.log("跳转成功");
					}
				})
			},
			toNew(){
				uni.navigateTo({
					url:"./newPage",
					success() {
						console.log("跳转成功");
					}
				})
			},
			toCart(){
				uni.navigateTo({
					url:"./cart",
					success() {
						console.log("跳转成功");
					}
				})
			}
		}
	}
</script>

<style>
	swiper{
		width: 750rpx;
		height: 380rpx;
	}
	swiper image{
		width: 100%;
		height: 100%;
	}
	.nav{
		display: flex;
		width: 100%;
		margin: 0 auto;
		border-bottom: 2px solid #ccc;
		padding: 10px 10px;
	}
	.nav_item{
		text-align: center;
		margin-left: 20px;
	}
	.nav_item image{
		display: block;
		width: 50px;
	}
</style>
